package com.hdu;


import com.hdu.config.DelayTaskClientProperties;
import com.hdu.controller.TaskTriggerController;
import com.hdu.exceptionHandler.GlobalExceptionHandler;
import com.hdu.service.TaskService;
import com.hdu.manager.DelayTaskManager;
import com.hdu.util.ApplicationContextHolder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(DelayTaskClientProperties.class)
public class KdkDelayTaskAutoConfiguration {


    @Bean
    @ConditionalOnClass(DelayTaskManager.class)
    public TaskTriggerController taskTriggerController(DelayTaskManager delayTaskManager) {
        return new TaskTriggerController(delayTaskManager);
    }

    @Bean
    public GlobalExceptionHandler globalExceptionHandler() {
        return new GlobalExceptionHandler();
    }

    @Bean
    @ConditionalOnClass(ApplicationContextHolder.class)
    public DelayTaskManager delayTaskManager(DelayTaskClientProperties delayTaskClientProperties) {
        return new DelayTaskManager(delayTaskClientProperties);
    }

    @Bean
    public ApplicationContextHolder applicationContextHolder() {
        return new ApplicationContextHolder();
    }

    @Bean
    public TaskService taskService(DelayTaskClientProperties delayTaskClientProperties) {
        return new TaskService(delayTaskClientProperties);
    }
}
